<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>文档</title>
  <link rel="stylesheet" href="/static/vendor/layui/css/layui.css">
  <link rel="stylesheet" href="/static/api/style.css">
  <script src="https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
  <script src="/static/vendor/layui/layui.all.js"></script>
  <script src="/static/vendor/function.js"></script>
  <style>.layui-form-label{width:150px;}.layui-input-block{margin-left: 180px;}</style>
</head>
<body>
    <div class="layui-main" style="padding: 20px;border: 1px solid #eee;margin:100px;">
        <pre class="layui-code">
            //post验证签名数组
            var url = "/zfcom/attachment/upimg";
            var partner = 5300;
            var sign = "";
        </pre>
        <div class="layui-upload">
          <button type="button" class="layui-btn"  lay-data="{url: '/', accept: 'images'}" id="test2">多图片上传</button>
          <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
            返回结果：
            <pre id="rs"></pre>
         </blockquote>
        </div>
    </div>

<script>
var url = "/comv1/attachment/upimg";
var partner = 5300;
var sign = "";
//多图片上传
layui.upload.render({
  elem: '#test2',
  data:{url:url,partner:partner,sign:sign},
  multiple:true,
  done: function(rs){
      var str = $("#rs").text();
      var str = str + formatJson(rs);
      $("#rs").text(str);
  }
});
/**
 * 格式化显示json格式数据
 */
function formatJson(json, options) {
    var reg = null,
        formatted = '',
        pad = 0,
        PADDING = '    ';
    options = options || {};
    options.newlineAfterColonIfBeforeBraceOrBracket = (options.newlineAfterColonIfBeforeBraceOrBracket === true) ? true : false;
    options.spaceAfterColon = (options.spaceAfterColon === false) ? false : true;
    if (typeof json !== 'string') {
        json = JSON.stringify(json);
    } else {
        json = JSON.parse(json);
        json = JSON.stringify(json);
    }
    reg = /([\{\}])/g;
    json = json.replace(reg, '\r\n$1\r\n');
    reg = /([\[\]])/g;
    json = json.replace(reg, '\r\n$1\r\n');
    reg = /(\,)/g;
    json = json.replace(reg, '$1\r\n');
    reg = /(\r\n\r\n)/g;
    json = json.replace(reg, '\r\n');
    reg = /\r\n\,/g;
    json = json.replace(reg, ',');
    if (!options.newlineAfterColonIfBeforeBraceOrBracket) {
        reg = /\:\r\n\{/g;
        json = json.replace(reg, ':{');
        reg = /\:\r\n\[/g;
        json = json.replace(reg, ':[');
    }
    if (options.spaceAfterColon) {
        reg = /\:/g;
        json = json.replace(reg, ': ');
    }
    $.each(json.split('\r\n'), function(index, node) {
        var i = 0,
            indent = 0,
            padding = '';
        if (node.match(/\{$/) || node.match(/\[$/)) {
            indent = 1;
        } else if (node.match(/\}/) || node.match(/\]/)) {
            if (pad !== 0) {
                pad -= 1;
            }
        } else {
            indent = 0;
        }
        for (i = 0; i < pad; i++) {
            padding += PADDING;
        }
        formatted += padding + node + '\r\n';
        pad += indent;
    });
    return formatted;
};
</script>
</body>
</html>
